package com.person.yan.a03_takeout1.presenter;


import android.app.Activity;
import android.os.Handler;
import android.text.format.DateFormat;
import android.widget.Toast;

import com.person.yan.a03_takeout1.bean.Goods;
import com.person.yan.a03_takeout1.contract.ListContract;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by ywy on 2017-10-09.
 */

public class ListPresenter {
    private final ListContract.View mView;
    private final Activity mActivity;
    private final List<Goods> list;

    public ListPresenter(ListContract.View view, Activity activity) {
        this.mView = view;
        this.mActivity = activity;
        list = new ArrayList<Goods>();
    }


    public void loadData(){

        mView.showLoading(true);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 15; i++) {
                    Goods goods = new Goods();
                    goods.setDesc("商品列表"+i+"----");
                    list.add(goods);
                }
                mView.showRv(list);

            }
        },2000);
    }

    public void deleteItem(int position) {
        list.remove(position);
        mView.refreashRv();

    }

    public void addItem(final int size) {
        mView.showLoading(true);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Goods goods = new Goods();
                int num = size;
                goods.setDesc("添加商品--"+ DateFormat.format("yyyy-MM-dd HH:mm:ss",new Date()));
                list.add(goods);
                mView.refreashRv();
                mView.showLoading(false);
            }
        }, 500);

    }
}
